var express = require('express');
var router = express.Router();
const multer =require('multer');
const storage = multer.diskStorage({
    destination(req, file, cb) {
        cb(null, './uploads')
    },
    filename(req, file, cb) {
        cb(null, Date.now() + '-' + file.originalname)
    }
})
const upload = multer({ storage })

const client= require('../client.js');
router.post('/',upload.array('files',20),async (req, res) => {
    let all=[];
    req.files.forEach((file,index)=>{
        all[index]=client.main(file.path,req.body.action)
    })
    let data= await Promise.all(all);
    let j=[];
    data.forEach(result=>{
        let r= JSON.parse(result)
        let data=JSON.parse(r.body.Data)
        j.push(data)
    })
    res.send(j);
});

module.exports = router;